package com.atguigu.gmall.realtime.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class KeywordUtil {
    public static List<String> analyse(String text){
        StringReader sr= new StringReader(text);
        IKSegmenter ik = new IKSegmenter(sr,true);
        Lexeme lex =null;
        List<String> keywordList = new ArrayList<>();
        while(true){
            try{
                if ((lex = ik.next()) != null){
                    String lexemeText = lex.getLexemeText();
                    keywordList.add(lexemeText);
                }else{
                    break;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return keywordList;
    }

    public static void main(String[] args) {
        String text="TCL 75Q10 75英寸 QLED原色量子点电视 安桥音响 AI声控智慧屏 超薄全面屏 MEMC防抖 3+32GB 平板电视等10件商品";
        System.out.println(KeywordUtil.analyse(text));
    }
}
